package com.xunfang.common.enumeration;

import lombok.Getter;

@Getter
public enum OrderStatus {
    NO_PAY(1, "待付款"),
    NO_SEND(2, "待发货"),
    NO_RECEIVE(3, "待收货"),
    NO_REVIEW(4, "待评价"),
    REFUNDING(5, "退款中"),
    AFTER_SALE(6, "售后中"),
    ALREADY_CANCEL(7, "已取消"),
    ALREADY_RETURN(8, "已退货"),
    ALREADY_RECEIVE(9, "已收货");

    private Integer code;
    private String describe;

    OrderStatus(int code, String describe) {
        this.code = code;
        this.describe = describe;
    }

    /**
     * 通过编码找到枚举对象
     */
    public static OrderStatus matchCode(int code) {
        OrderStatus status = null;
        //values()方法是枚举类自带的方法，获取当前所有枚举项的数组
        OrderStatus[] values = values();
        for (OrderStatus value : values) {
            if (value.getCode() == code) {
                status = value;
                break;
            }
        }
        return status;
    }

    /**
     * 通过描述找到枚举对象
     */
    public static OrderStatus matchDescribe(String describe) {
        OrderStatus status = null;
        OrderStatus[] values = values();
        for (OrderStatus OrderStatus : values) {
            if (OrderStatus.getDescribe().equals(describe)) {
                status = OrderStatus;
                break;
            }
        }
        return status;
    }
}